package org.bugjail.servlet.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bugjail.data.TestCaseExecution;
import org.bugjail.dataaccess.DAOFactory;
import org.bugjail.dataaccess.objects.TestCaseExecutionDAO;
import org.bugjail.servlet.BasicServlet;

/**
 * Servlet implementation class for Servlet: NewSuiteServlet
 *
 */
 public class ExecuteTestCaseServlet extends BasicServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public ExecuteTestCaseServlet() {
		super();
	}   	

	@Override
	protected void action(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		int tceid = Integer.parseInt(request.getParameter("tceid"));
		TestCaseExecution tce = DAOFactory.getDAOFactory().getTestCaseExecutionDAO().retrieveById(tceid);
		
		TestCaseExecutionDAO dao = DAOFactory.getDAOFactory().getTestCaseExecutionDAO();
		tce.setAssignedUser(getLoggedUser());
		tce.setComments(request.getParameter("comments"));
		tce.setResult(Integer.parseInt(request.getParameter("result")));
		tce.setCrsRelated(request.getParameter("issuesrelated"));
		dao.execute(tce);
		response.sendRedirect("TestCaseExecutionDetailsServlet?tceid="+tceid);
	}

	@Override
	protected void beforeAction(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}   	  	    
}